/*
 * @Author: minglic minglic@foxmail.com
 * @Date: 2023-10-21 09:37:18
 * @LastEditors: minglic minglic@foxmail.com
 * @LastEditTime: 2023-10-21 14:45:10
 * @FilePath: \go2023\core\utils\r.go
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
package utils

import "github.com/gin-gonic/gin"

//固定的响应数据格式
type R struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
	Data    any    `json:"data"`
}

//通用的封装数据的函数
func ResponseJson(c *gin.Context, err error, data any) {
	if err == nil {
		c.JSON(200, R{Code: 20000, Message: "SUCEESS", Data: data})
	} else {
		c.JSON(200, R{Code: 50000, Message: err.Error(), Data: data})
	}
}
